/*
 * @Author: 江舟 jijiangzhou@recycloud.cn
 * @Date: 2024-03-26 17:47:38
 * @LastEditors: 江舟 jijiangzhou@recycloud.cn
 * @LastEditTime: 2024-04-18 15:27:34
 * @FilePath: \vite-project\src\components\org\OrgFormCont.tsx
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */
import { ORG_TYPES } from '@/constant';
import { Form, Input, Select, TreeSelect } from 'antd';

interface OrgFormContProps {
	treeData?: any[];
	parentNode?: any;
}

const OrgFormCont: React.FC<OrgFormContProps> = ({ treeData, parentNode }) => {
	return (
		<>
			<Form.Item
				name="parentId"
				label="上级机构"
				rules={[
					{ required: true, message: '请选择上级机构' },
					{
						validator: (rule, value) => {
							if (parentNode?.id && value === parentNode?.id) {
								return Promise.reject(new Error(`上级机构不可以选本身`));
							} else if (value) {
								return Promise.resolve();
							} else {
								return Promise.reject(new Error('请选择上级机构'));
							}
						},
					},
				]}>
				<TreeSelect
					treeDefaultExpandAll
					placeholder="请选择上级机构"
					treeData={treeData}
					allowClear
					fieldNames={{
						label: 'name',
						value: 'id',
					}}
				/>
			</Form.Item>
			<Form.Item name="name" label="机构名称" rules={[{ required: true, message: '请输入机构名称' }]}>
				<Input placeholder="请输入机构名称" maxLength={18} />
			</Form.Item>
			<Form.Item name="sortNo" label="排序">
				<Input type="number" placeholder="请输入排序" min={0} />
			</Form.Item>
			<Form.Item name="socialOrganizationId" label="机构代码">
				<Input placeholder="请输入机构代码" />
			</Form.Item>
			<Form.Item name="type" label="组织形态属性" rules={[{ required: true, message: '请选择组织形态属性' }]}>
				<Select placeholder="请选择组织形态属性" options={ORG_TYPES} />
			</Form.Item>
		</>
	);
};

export default OrgFormCont;
